package com.ruoyi.huanghefd.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.huanghefd.domain.twotickets;
import com.ruoyi.huanghefd.domain.twoticketsTJ;
import com.ruoyi.huanghefd.service.twoticketsService;
import com.ruoyi.huanghefd.utils.PageBean;
import com.ruoyi.huanghefd.mapper.twoticketsMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author gnplum
 * @Date 2024/1/4 21:45
 * @PackageName:com.ruoyi.huanghefd.service.impl
 * @ClassName: twoticketsServiceImpl
 * @Description: 两票查询服务
 * @Version 1.0
 */
@Service
public class twoticketsServiceImpl extends ServiceImpl<twoticketsMapper, twotickets> implements twoticketsService {
    private static final Logger log = LoggerFactory.getLogger(twoticketsServiceImpl.class);

    @Resource
    private twoticketsMapper twoticketsMapper;

    @Override
    public PageBean twoticketsQuery(String ticketSort, String ticketCode, String ticketName, String ticketType, String ticketState, String planStarttime, String planEndtime, String isTimeout, String dept, String principal, int pageNum, int pageSize) {
        PageBean pageBean = new PageBean();
        if (pageNum > 0 && pageSize > 0) {
            int totalRecord = 0;
            if (ticketSort.equals("1")) {
                totalRecord = twoticketsMapper.getWorksheetNum(ticketCode, ticketName, ticketType, ticketState, planStarttime, planEndtime, isTimeout, dept, principal);
            } else if (ticketSort.equals("2")) {
                totalRecord = twoticketsMapper.getMakesheetNum(ticketCode, ticketName, ticketType, ticketState, planStarttime, planEndtime, dept, principal);
            } else {
                pageBean.setCode(500);
                pageBean.setFailMsg("查询类型有误，1-工作票查询 2-操作票查询");
                return pageBean;
            }
            pageBean = new PageBean(pageNum, pageSize, totalRecord);

            //从该行开始拿数据
            int startIndex = (pageNum - 1) * pageSize;
            pageBean.setStartIndex(startIndex);
            pageBean.setCode(200);

            //数据集合
            List<twotickets> twoticketsList = new ArrayList<>();
            if (ticketSort.equals("1")) {
                twoticketsList = twoticketsMapper.worksheetQueryByPage(ticketCode, ticketName, ticketType, ticketState, planStarttime, planEndtime, isTimeout, dept, principal, startIndex, pageSize);
                pageBean.setList(twoticketsList);
            } else if (ticketSort.equals("2")) {
                twoticketsList = twoticketsMapper.makesheetQueryByPage(ticketCode, ticketName, ticketType, ticketState, planStarttime, planEndtime, dept, principal, startIndex, pageSize);
                pageBean.setList(twoticketsList);
            } else {
                pageBean.setCode(500);
                pageBean.setFailMsg("查询类型有误，1-工作票查询 2-操作票查询");
                return pageBean;
            }
            pageBean.setSuccessMsg("查询成功！");
        } else {
            pageBean.setCode(500);
            pageBean.setFailMsg("查询失败！");
        }
        return pageBean;
    }

    @Override
    public PageBean twoticketsTJQuery(String ticketSort, String dept, String ticketType, String currYearNum, String currMonthNum, int pageNum, int pageSize) {
        PageBean pageBean = new PageBean();
        if (pageNum > 0 && pageSize > 0) {
            int totalRecord = 0;
            if (ticketSort.equals("1")) {
                totalRecord = twoticketsMapper.getTJWorksheetNum(dept, ticketType, currYearNum, currMonthNum);
            } else if (ticketSort.equals("2")) {
                totalRecord = twoticketsMapper.getTJMakesheetNum(dept, ticketType, currYearNum, currMonthNum);
            } else {
                pageBean.setCode(500);
                pageBean.setFailMsg("查询类型有误，1-工作票查询 2-操作票查询");
                return pageBean;
            }
            pageBean = new PageBean(pageNum, pageSize, totalRecord);

            //从该行开始拿数据
            int startIndex = (pageNum - 1) * pageSize;
            pageBean.setStartIndex(startIndex);
            pageBean.setCode(200);

            //数据集合
            List<twoticketsTJ> twoticketsTJList = new ArrayList<>();
            if (ticketSort.equals("1")) {
                twoticketsTJList = twoticketsMapper.TJworksheetQueryByPage(dept, ticketType, currYearNum, currMonthNum, startIndex, pageSize);
                pageBean.setList(twoticketsTJList);
            } else if (ticketSort.equals("2")) {
                twoticketsTJList = twoticketsMapper.TJmakesheetQueryByPage(dept, ticketType, currYearNum, currMonthNum, startIndex, pageSize);
                pageBean.setList(twoticketsTJList);
            } else {
                pageBean.setCode(500);
                pageBean.setFailMsg("查询类型有误，1-工作票查询 2-操作票查询");
                return pageBean;
            }
            pageBean.setSuccessMsg("查询成功！");
        } else {
            pageBean.setCode(500);
            pageBean.setFailMsg("查询失败！");
        }
        return pageBean;
    }


}
